﻿using System.CodeDom.Compiler;

namespace ShadowCode.Injection.Injections;

public class ClassUnit(TransformData data, ClassDeclarationSyntax classSyntax)
    : InjectionUnitBase(data)
{
    private INamedTypeSymbol? type;

    public override SyntaxNode? Node { get; set; } = classSyntax;

    /// <summary>
    /// 实现的类型
    /// </summary>
    public INamedTypeSymbol Type => type ??= GetAttributeType(classSyntax);

    protected override string CreateGroupKey() => Type.ToDisplayString();

    protected override INamedTypeSymbol CreateTypeDeclaration() => Type;

    internal override bool CanSimple => true;

    internal override void ImplementBuild(InjectionAttribute attribute,
        IndentedTextWriter writer, List<string> arguments)
    {
        arguments.Add("implement");
        writer.WriteLine($"var implement = typeof({Type.ToDisplayString()});");
    }
}